//
//  ViewController.m
//  JiCaiBao
//
//  Created by rgx on 16/10/21.
//  Copyright © 2016年 rgx. All rights reserved.
//

#import "RGXViewController.h"

@interface RGXViewController ()

@end

@implementation RGXViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)setShowTitle:(NSString*)title
{
    if( ![title isKindOfClass:[NSString class]] ||
       [title length]==0 )
        return;
    if( [[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0 )
    {
        if(self.navigationItem.titleView && [self.navigationItem.titleView isKindOfClass:[UILabel class]]){
            UILabel *temp = (UILabel*)self.navigationItem.titleView;
            temp.text = title;
            return;
        }
        UILabel *title_f = [[UILabel alloc]init];
        title_f.frame = CGRectMake(0, 0, 100, 30);
        title_f.font = [UIFont systemFontOfSize:18];
        title_f.textColor = [UIColor whiteColor];
        [title_f setBackgroundColor:[UIColor clearColor]];
        [title_f setTextAlignment:NSTextAlignmentCenter];
        title_f.text = title;
        self.navigationItem.titleView = title_f;
    }
    else
    {
        self.title = title;
    }
}

-(void)initLeftNavigationBarItem
{
    
    UIImage *pLeftImage = [UIImage imageNamed:@"common_return_icon_nor.png"];
    UIButton *pLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    pLeftButton.frame = CGRectMake(-10, 0, 44, 44);
    [pLeftButton setBackgroundImage:pLeftImage forState:UIControlStateNormal];
    [pLeftButton setBackgroundImage:[UIImage imageNamed:@"common_return_icon_sel.png"] forState:UIControlStateHighlighted];
    [pLeftButton addTarget:self action:@selector(backButtonEvents:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *pLeftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:pLeftButton];
    UIBarButtonItem *negativeSpacer = [[ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemFixedSpace target : nil action : nil ];
    negativeSpacer. width = - 10 ;//这个数值可以根据情况自由变化
    self.navigationItem.leftBarButtonItems = @[ negativeSpacer, pLeftButtonItem ] ;
    //    self.navigationItem.leftBarButtonItem = pLeftButtonItem;
    
}
-(void)backButtonEvents:(id)sender
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

#pragma 时间格式转换
- (NSString *)getTimeStr:(NSString *)str
{
    long long  date1 = (long long )[str longLongValue]/1000;

    NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:date1];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    [df setDateFormat:@"yyyy-MM-dd"];
    
    return [df stringFromDate:date2];
}


-(void)initLeftNavigationBarItem_PreVC
{
    
    UIButton *pLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    pLeftButton.frame = CGRectMake(-10, 0, 44, 44);
    [pLeftButton setTitle:@"取消" forState:UIControlStateNormal];
    [pLeftButton addTarget:self action:@selector(backButtonEvents_PreVC:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *pLeftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:pLeftButton];
    UIBarButtonItem *negativeSpacer = [[ UIBarButtonItem alloc ] initWithBarButtonSystemItem : UIBarButtonSystemItemFixedSpace target : nil action : nil ];
    negativeSpacer. width = - 10 ;//这个数值可以根据情况自由变化
    self.navigationItem.leftBarButtonItems = @[ negativeSpacer, pLeftButtonItem ] ;
    //    self.navigationItem.leftBarButtonItem = pLeftButtonItem;
    
}


- (void)backButtonEvents_PreVC:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
